package logic

import (
	"api/internal/svc"
	"api/internal/types"
	"api/service"
	"context"

	"github.com/zeromicro/go-zero/core/logx"
)

type BindSocketLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewBindSocketLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BindSocketLogic {
	return &BindSocketLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *BindSocketLogic) BindSocket(req *types.RequestBindSocket) (resp *types.ResponseMsg, err error) {
	// 将信息保存在redis中
	redis := l.svcCtx.RedisPool.Get()
	defer redis.Close()

	busService := service.NewBusinessService(l.ctx, l.svcCtx)
	busService.SaveBussSocket(redis, req.Phone, req.Fd)
	return service.ReturnOk()
}
